package com.collection.common.base;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

/**
 * action基类
 * @author 冯勇
 *
 */
public class BaseAction extends ActionSupport {

	private static final long serialVersionUID = 8581692816877257371L;
	
	private HttpServletRequest request;
	private HttpServletResponse response;
	private String message;

	public HttpServletRequest getRequest() {
		request = ServletActionContext.getRequest();
		return request;
	}

	public HttpServletResponse getResponse() {
		response = ServletActionContext.getResponse();
		return response;
	}


	public HttpSession getSession() {
		if(getRequest() != null) {
			return request.getSession();
		}
		return null;
	}


	public PrintWriter getOut() {
		if(getResponse() != null) {
			try {
				return response.getWriter();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	public String getRealPath() {
		return ServletActionContext.getServletContext().getRealPath("/");
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
